
package com.tenentia.pcmps.swm.business.implementation;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.tenentia.pcmps.swm.Constants;
import com.tenentia.pcmps.swm.business.BusinessLogicException;
import com.tenentia.pcmps.swm.business.interfaces.PDFTemplatesManager;
import com.tenentia.pcmps.swm.data.DataAccessObjectsFactory;
import com.tenentia.pcmps.swm.data.beans.PDFTemplate;
import com.tenentia.pcmps.swm.data.interfaces.PDFTemplatesDAO;

/**
 * 
 * @author tEnEntia, S.L.N.E.
 * 
 */
public class PDFTemplatesManagerImpl implements PDFTemplatesManager {

	private static final Logger LOGGER = Logger.getLogger(PDFTemplatesManagerImpl.class.getPackage().getName());

	PDFTemplatesManagerImpl() {

		super();
	}

	@Override
	public void delete(PDFTemplate template) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			dataAccessObject.delete(template);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}

	}

	@Override
	public PDFTemplate get(PDFTemplate template) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.get(template);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public List<PDFTemplate> getTableItemsByRange(Object filterParameters, Object sortParameters, Integer firstRow, Integer numberOfRows) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.getTableItemsByRange(filterParameters, sortParameters, firstRow, numberOfRows);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public Integer getTableRowCount(Object filterParameters) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.getTableRowCount(filterParameters);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public PDFTemplate getPDFTemplateByAlias(String alias) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.getPDFTemplateByAlias(alias);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public PDFTemplate getPDFTemplateByClassNameAndDate(String className, Date classDate) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.getPDFTemplateByClassNameAndDate(className, classDate);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public PDFTemplate save(PDFTemplate template) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.save(template);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public PDFTemplate update(PDFTemplate template) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			PDFTemplatesDAO dataAccessObject = (PDFTemplatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PDF_TEMPLATES_DAO);
			return dataAccessObject.update(template);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

}
